<?php
if (isset($_POST['pic'])) {
 
  $fileName=time().rand(1,9999).'.png';
  
  if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $_POST['pic'], $result)){
 
       file_put_contents('./he/'.$fileName, base64_decode(str_replace($result[1], '', $_POST['pic'])) );

   }
 
  
  echo json_encode(array('f' =>$fileName));
  
}

